import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

public class Triangle {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		try
		{
			System.out.println("This program determines if a triangle is equilateral, isosceles, or scalene based on user's input \n");
			
			int[] anArray;              
			anArray = new int[3];      

			for (int i = 1; i <= 3; i++)
			{
				System.out.println("Enter triangle length of side " + i + ": ");
			    BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
			    String side = bufferRead.readLine();
			    
			    boolean isInteger = Pattern.matches("^\\d*", side);
			    
			    // Check to see if input is a valid number. If not, keep prompting user to enter valid number
			    while (!isInteger)
			    {
			    	System.out.println("Invaid triangle length. Please enter a numeric triangle length for side " + i + ": ");
				    bufferRead = new BufferedReader(new InputStreamReader(System.in));
				    side = bufferRead.readLine();
				    
				    isInteger = Pattern.matches("^\\d*", side);
			    
			    }
			    
			    anArray[i - 1] = Integer.parseInt(side);

			}
			
			String result = "";
			
			// Check if triangle is equilateral, scalene, or isosceles
		    if (anArray[0] == anArray[1] && anArray[1] == anArray[2] && anArray[0] == anArray[2])
		    {
		    	result = "equilateral";
		    } 
		    else if (anArray[0] != anArray[1] && anArray[1] != anArray[2] && anArray[0] != anArray[2])
		    {
		    	result = "scalene";
		    }
		    else 
		    {		    	
		    	result = "isosceles";
		    }
		    
		    // Check if triangle is a right triangle
		    if (((anArray[0] * anArray[0]) + (anArray[1] * anArray[1]) == (anArray[2] * anArray[2])) ||
		    	((anArray[1] * anArray[1]) + (anArray[2] * anArray[2]) == (anArray[0] * anArray[0])) ||
		    	((anArray[0] * anArray[0]) + (anArray[2] * anArray[2]) == (anArray[1] * anArray[1])))
		    {
		    	result += " and right";
		    } 
		    
		    System.out.println("A triangle with lengths " + anArray[0] + ", " + anArray[1] + ", and " + anArray[2] + " is " + result);
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}


	}
	

}
